﻿using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Utilities.Encoders;
using System.Text;

namespace 加密算法
{
    public static class SM3Helper
    {
        public static string Encrypt(string str)
        {
            byte[] plaintextBytes = Encoding.UTF8.GetBytes(str);
            IDigest digest = new SM3Digest();
            byte[] hashBytes = new byte[digest.GetDigestSize()];
            digest.BlockUpdate(plaintextBytes, 0, plaintextBytes.Length);
            digest.DoFinal(hashBytes, 0);
            string hashString = Hex.ToHexString(hashBytes);
            return hashString;
        }
    }
}
